const config = require('../config');

const attestationApi = config.attestationApi.url;
const axios = require('axios');

const Web3 = require('web3');

let txHash = "0x06681916b8fb06e3759e76511c798c78c8053b7c6fe33aa149736dda708448a2";

let url = config.goerli.urls[0];

const run = async ()=>{
    let web3 = new Web3(new Web3.providers.HttpProvider(url));
    const eventTopic = web3.utils.keccak256('MessageSent(bytes)');

    const transactionReceipt = await web3.eth.getTransactionReceipt(txHash);
    const log = transactionReceipt.logs.find((l) => l.topics[0] === eventTopic)
    console.log("log : ", log);
    const messageBytes = web3.eth.abi.decodeParameters(['bytes'], log.data)[0]
    console.log("messageBytes: ", messageBytes);
    const messageHash = web3.utils.keccak256(messageBytes);


    console.log('messageHash: ', messageHash);
    let circleUrl = attestationApi + messageHash;
    console.log('circleUrl: ', circleUrl);

    //const res = await axios.get(circleUrl);
    //console.log('res.data', res.data);
}
run();

/*
*circleUrl:  https://iris-api-sandbox.circle.com/attestations/0x54a23e7216478bae3223c2666d5d86971b0a2f80fb2dc04fdb50d9e655cc63a2
res.data {
  attestation: '0xd18c8ffc467c6620723149e5d9f3cde9810bc9a8fc4bb515b2deefa5fa70d5db5e1809c06492eaa90efbc5ed381d8eaffe78ba486672a31065f16bff
9aa193f81b02220e21d71dd4680b8b2daeb184fab1ec7d9e216af5ea889306357a37cb6ba71c622660d790d50160d360355ef1fbcde8fdb651bd7697bfdc72b512befebe44
1c',
  status: 'complete'
}

* */